{extend name="app/admin/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">操作提示</h2>
        <ul class="layui-colla-content layui-show">
            <li>当前页面针对视频号申请进行管理操作。</li>
        </ul>
    </div>
</div>

<div class="ns-screen layui-collapse" lay-filter="selection_panel">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">筛选</h2>

        <form class="layui-colla-content layui-form layui-show">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">视频号名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" placeholder="请输入视频号名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">微信号：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="wx_username" name="wx_username" placeholder="请输入微信号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">商家名称：</label>
                    <div class="layui-input-inline">
                        <select name="site_id" lay-filter="site_id">
                            <option value="">全部</option>
                            {volist name="$shop_list" id="shop_list"}
                            <option value="{$shop_list.site_id}">{$shop_list.site_name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            </div>

            <input type="hidden" name="status"/>
            <div class="ns-form-row">
                <button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
</div>

<div class="layui-tab ns-table-tab" lay-filter="video_list_tab">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="">全部</li>
        <li lay-id="0" data-type="status">待审核</li>
        <li lay-id="1" data-type="status">审核成功</li>
        <li lay-id="-1" data-type="status">审核失败</li>
    </ul>
    <div class="layui-tab-content">
        <table id="video_list" lay-filter="video_list"></table>
    </div>
</div>

<!-- 工具栏操作 -->
<script type="text/html" id="operation">
    {{#  if(d.status == 0){ }}
    <div class="ns-table-btn">
        <a class="layui-btn" lay-event="video_pass">通过</a>
        <a class="layui-btn" id="apply_message" lay-event="video_refuse">拒绝</a>
    </div>
    {{#  } }}
</script>

<!-- 申请状态 -->
<script type="text/html" id="status">
    {{#  if(d.status == 0){ }}
    <span style="color: gray;">待审核</span>
    {{#  } }}
    {{#  if(d.status == 1){ }}
    <span style="color: green;">审核成功</span>
    {{#  } }}
    {{#  if(d.status == -1){ }}
    <span style="color: red;">审核失败</span>
    {{#  } }}
</script>
{/block}
{block name="script"}
<script type="text/html" id="contend">
    <div class="list-detail layui-table-overflow">
        <p style="text-align: left;">
            <span style="white-space: initial;">{{d.refuse}}</span>
        </p>
    </div>
</script>
<script>
    var element;
    layui.use(['form', 'layer', 'laydate', 'element'], function () {
        var table,
            form = layui.form,
            layer = layui.layer,
            element = layui.element;
        form.render();

        //监听Tab切换，以改变地址hash值
        element.on('tab(video_list_tab)', function () {
            var type = this.getAttribute('data-type');
            if (type) {
                var id = this.getAttribute('lay-id');
                $("input[name='" + type + "']").val(id);
                $("button[lay-filter='search']").click()
            } else {
                $("input[name='status']").val("");
                $("button[lay-filter='search']").click()
            }
        });

        /**
         * 搜索功能
         */
        form.on('submit(search)', function (data) {
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        /**
         * 表格加载
         */
        table = new Table({
            elem: '#video_list',
            url: ns.url("shopcomponent://admin/video/lists"),
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            },
            cols: [
                [ {
                    width: '10%',
                    field: 'name',
                    title: '视频号名称',
                    unresize: 'false',
                },{
                    width: '10%',
                    field: 'wx_username',
                    title: '申请微信号',
                    unresize: 'false',
                }, {
                    width: '12%',
                    field: 'site_name',
                    title: '商家名称',
                    unresize: 'false',
                }, {
                    width: '10%',
                    field: 'status',
                    title: '状态',
                    unresize: 'false',
                    templet: '#status',
                }, {
                    width: '15%',
                    field: 'refuse',
                    title: '审核结果',
                    unresize: 'false',
                    toolbar: '#contend',
                }, {
                    width: '13%',
                    field: 'create_time',
                    title: '申请时间',
                    unresize: 'false',
                    templet: function (data) {
                        return ns.time_to_date(data.create_time);
                    },
                }, {
                    width: '15%',
                    title: '操作',
                    toolbar: '#operation',
                    unresize: 'false'
                }
                ]
            ]
        });


        /**
         * 监听工具栏操作
         */
        table.tool(function (obj) {
            var data = obj.data,
                event = obj.event;
            switch (event) {
                case 'video_pass':  //审核通过
                    applyPass(data);
                    break;
                case 'video_refuse':  //拒绝
                    applyRefuse(data);
                    break;
            }
        });

        // 通过审核
        function applyPass(data) {
            layer.confirm('确定要通过审核吗?', function () {
                $.ajax({
                    url: ns.url("shopcomponent://admin/video/pass"),
                    data: {
                        "id": data.id,
                    },
                    dataType: 'JSON', //服务器返回json格式数据
                    type: 'POST', //HTTP请求类型
                    success: function (res) {
                        layer.msg(res.message);
                        if (res.code == 0) {
                            table.reload();
                        }
                    }
                });
            });
        }

        // 拒绝通过
        function applyRefuse(data) {
            /**
             * 拒绝理由弹窗
             */
            layer.prompt({
                formType: 2,
                value: '',
                title: '请输入拒绝理由',
                area: ['300px', '100px'],//自定义文本域宽高
                yes: function (index, layero) {
                    // 获取文本框输入的值
                    var value = layero.find(".layui-layer-input").val();
                    if (value) {
                        $.ajax({
                            url: ns.url("shopcomponent://admin/video/refuse"),
                            data: {
                                "id": data.id,
                                "reason": value
                            },
                            dataType: 'JSON', //服务器返回json格式数据
                            type: 'POST', //HTTP请求类型
                            success: function (res) {
                                layer.msg(res.message);
                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                        layer.close(index);
                    } else {
                        layer.msg('请输入拒绝原因!', {icon: 5, anim: 6});
                    }
                }
            });
        }
    });

</script>
{/block}